'use strict'

module.exports = app => {
	const { STRING, INTEGER, DATE, Number } = app.Sequelize
	const UserInfo = app.model.define('userInfo', {
		id: { type: INTEGER, primaryKey: true, autoIncrement: true },
		userId: {
			type: INTEGER,
			comment: '用户ID',
		},
		name: {
			type: STRING,
			field: '_name',
			comment: '用户昵称',
		},
		avatar: {
			type: STRING,
			field: '_avatar',
			comment: '用户头像',
		},
		mobile: {
			type: STRING(11),
			field: '_mobile',
			comment: '手机号',
		},
		proviceId: {
			type: INTEGER,
			field: 'provice_id',
			comment: '省ID',
		},
		cityId: {
			type: INTEGER,
			field: 'city_id',
			comment: '市ID',
		},
		areaId: {
			type: INTEGER,
			field: 'area_id',
			comment: '区ID',
		},
		role: {
			type: INTEGER,
			field: '_role',
			comment: '权限',
		},
		createdAt: DATE,
		updatedAt: DATE,
	})
	UserInfo.associate = function () {
		app.model.UserInfo.belongsTo(app.model.Province, {
			foreignKey: 'proviceId',
			targetKey: 'provinceCode',
		})
		app.model.UserInfo.belongsTo(app.model.City, {
			foreignKey: 'cityId',
			targetKey: 'cityCode',
		})
		app.model.UserInfo.belongsTo(app.model.Area, {
			foreignKey: 'areaId',
			targetKey: 'areaCode',
		})
	}
	return UserInfo
}
